package com.zzq.guli.service.vod.controller;


import com.zzq.guli.service.base.result.R;
import com.zzq.guli.service.vod.service.VodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;


@CrossOrigin
@RequestMapping("admin/vod")
@RestController
public class VodController {

    /**
     * 阿里云视频上传
     */


    @Autowired
    VodService vodService;

    @RequestMapping("upload")
    public R VideoUp(MultipartFile file){
        //1.本地文件上传
        if(file!=null){
            InputStream inputStream = null;
            try {
                inputStream = file.getInputStream();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            String fileName =file.getOriginalFilename();
            String title=file.getName();
            String url=vodService.vodUpload(title,fileName,inputStream);
            String originalFilename = file.getOriginalFilename();
            return R.ok().data("url",url).data("originalFilename",originalFilename);
        }




        return null;
    }




}
